package com.ynny.Dao.Imp;

import com.ynny.Dao.ScoreManageDao;
import com.ynny.Entity.Score;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.List;

@Repository
public class ScoreManageImp  implements ScoreManageDao {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    public int addScore(String number, String course, Double score){
        String sql = "insert into score(number,courses,score) values(?,?,?)";
        return jdbcTemplate.update(sql,number,course,score);
    }

    @Override
    public Score queryScoreByNumber(String number) {
     String sql="select *from score where =?";
     return jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<>(Score.class), number);
     }


    @Override
    public int updateScore(String number, String courses, Double score) {
        String sql="update score set score=? where number=? and courses=?";
        return jdbcTemplate.update(sql, score, number);
    }

    @Override
    public List<Score> queryAllScore() {
        String sql="select *from score";
        return jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(Score.class));
    }


}
